home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / generic / shadebox.tex < prev    next >
Encoding:
Text File  |  1992-08-26  |  5.3 KB  |  160 lines

  1. %% Save file as: SHADEBOX.TEX           Source: FILESERV@SHSU.BITNET  
  2. %% Author: Leo@vaxc.cc.monash.edu.au 
  3. %% Original Source: Posted by Jim Hefferon <HEFFERON@SMCVAX.BITNET> to
  4. %%                  INFO-TeX on Thu, 16 Jan 1992 11:21 EST
  5.  
  6. %----------------------------------------------------------------------------
  7. \newbox\graybox
  8. \newdimen\xgrayspace
  9. \newdimen\ygrayspace
  10. %----------------------------------------------------------------------------
  11. %
  12. % The following \TeX code was based on previous work by
  13. %
  14. %            Je'ro^me Maillot, maillot@bora.inria.fr
  15. %
  16. %----------------------------------------------------------------------------
  17. %
  18. % Use the following for one or more words within a line.
  19. %
  20. \def\textshade#1#2{%
  21.     \xgrayspace=4pt%
  22.     \ygrayspace=4pt%
  23.     \def\grayshade{0.95}%
  24.     \def\linewidth{1}%
  25.     \def\theradius{5}%
  26.     \setbox\graybox=\hbox{\surroundboxa{#2}}%
  27.     \hbox{%
  28.     \hbox to 0pt{%
  29.     \special{"gsave newpath 0 0 moveto                                %
  30.         0                                    1 copy /xmin exch store  %
  31.         \number\dp\graybox \space -65536 div 1 copy /ymin exch store  %
  32.         \number\wd\graybox \space  65536 div 1 copy /xmax exch store  %
  33.         \number\ht\graybox \space  65536 div 1 copy /ymax exch store  %
  34.         \theradius\space                            /radius exch store
  35.         \linewidth\space                            /linewidth exch store
  36.         \grayshade\space                            /grayshade exch store
  37.         #1 grestore}}%
  38.     \box\graybox}}%
  39. %
  40. % Use the following for paragraphs.
  41. %
  42. \def\parashade#1#2{%
  43.     \xgrayspace=10pt%
  44.     \ygrayspace=10pt%
  45.     \def\grayshade{0.95}%
  46.     \def\linewidth{2}%
  47.     \def\theradius{10}%
  48.     \def\thevskip{15pt}%
  49.     \setbox\graybox=\hbox{\surroundboxb{#2}}%
  50.     \vskip\thevskip
  51.     \hbox{%
  52.     \hbox to 0pt{%
  53.     \special{"gsave newpath 0 0 moveto                                %
  54.         0                                    1 copy /xmin exch store  %
  55.         \number\dp\graybox \space -65536 div 1 copy /ymin exch store  %
  56.         \number\wd\graybox \space  65536 div 1 copy /xmax exch store  %
  57.         \number\ht\graybox \space  65536 div 1 copy /ymax exch store  %
  58.         \theradius\space                            /radius exch store
  59.         \linewidth\space                            /linewidth exch store
  60.         \grayshade\space                            /grayshade exch store
  61.         #1 grestore}}%
  62.      \box\graybox}%
  63.      \vskip\thevskip%
  64. }%
  65. %----------------------------------------------------------------------------
  66. %
  67. % A pair of box macros. Each builds a slightly oversized box
  68. % containing the text. The text is centred both in the vertical
  69. % horizontal directions.
  70. %
  71. % Use the following for one or more words within a line.
  72. %
  73. \long\def\surroundboxa#1{\leavevmode\hbox{\vtop{%
  74. \vbox{\kern\ygrayspace%
  75. \hbox{\kern\xgrayspace#1%
  76.       \kern\xgrayspace}}\kern\ygrayspace}}}
  77. %
  78. % Use the following for a paragraphs.
  79. %
  80. \long\def\surroundboxb#1{\leavevmode\hbox{\vtop{%
  81. \vbox{\kern\ygrayspace%
  82. \hbox{\kern\xgrayspace\vbox{\advance\hsize-2\xgrayspace#1}%
  83.       \kern\xgrayspace}}\kern\ygrayspace}}}
  84. %----------------------------------------------------------------------------
  85. %
  86. % Here are some simple PostScript routines.
  87. %
  88. % The TeX command \PScommands must be called before any of the
  89. % shading routines can be used.
  90. %
  91. \long\def\PScommands{\special{! TeXDict begin
  92. %
  93. /sharpbox{%
  94.            newpath
  95.            xmin ymin moveto
  96.            xmin ymax lineto
  97.            xmax ymax lineto
  98.            xmax ymin lineto
  99.            xmin ymin lineto
  100.            closepath
  101.           }bind def
  102. %
  103. /roundbox{%
  104.            newpath
  105.            xmin radius add ymin moveto
  106.            xmax ymin xmax ymax radius arcto
  107.            xmax ymax xmin ymax radius arcto
  108.            xmin ymax xmin ymin radius arcto
  109.            xmin ymin xmax ymin radius arcto 16 {pop} repeat
  110.            closepath
  111.           }bind def
  112. %
  113. /sharpcorners{%
  114.                sharpbox gsave grayshade setgray fill grestore
  115.                linewidth setlinewidth stroke
  116.               }bind def
  117. %
  118. /plainbox{%
  119.            sharpbox grayshade setgray fill
  120.           }bind def
  121. %
  122. /roundcorners{%
  123.                roundbox gsave grayshade setgray fill grestore
  124.                linewidth setlinewidth stroke
  125.               }bind def
  126. %
  127. end}%                   Closes dictionnary
  128. }%
  129.  
  130. \PScommands
  131.  
  132. This is a test of a\ \textshade{roundcorners}{shaded box} routine.
  133. %
  134. This is another test of a\ \textshade{sharpcorners}{shaded box} routine
  135.  
  136. \parashade{roundcorners}{%
  137. This is one very long line which I expect will be broken over one or more
  138. lines. The idea is to have this paragraph enclosed in a shaded box. I'll
  139. just keep on typing until I can be sure that there are more than two lines
  140. in this paragraph. I expect that this should be well and truely sufficient
  141. to test this macro.
  142. }
  143. \parashade{sharpcorners}{%
  144. This is one very long line which I expect will be broken over one or more
  145. lines. The idea is to have this paragraph enclosed in a shaded box. I'll
  146. just keep on typing until I can be sure that there are more than two lines
  147. in this paragraph. I expect that this should be well and truely sufficient
  148. to test this macro.
  149. }
  150.  
  151. The field equations of General Relativity are\ %
  152. %
  153. \textshade{roundcorners}{\hbox{$G_{\mu\nu} = kT_{\mu\nu}$}}
  154.  
  155. They can also be written as
  156.  
  157. \parashade{sharpcorners}{$$R_{\mu\nu}-{1\over2}g_{\mu\nu}R = kT_{\mu\nu}$$}
  158.  
  159. \bye
  160.